 
package ibms_rcp.worker.parts;

import ibms_rcp.dao.EstateManager;
import ibms_rcp.model.Building;
import ibms_rcp.model.Floor;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.nebula.widgets.calendarcombo.CalendarCombo;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.widgets.Button;

public class AddPart {
	
	//姓名
	private Text nameText;
	//性别
	private Combo genderCombo;
	//部门
	private ComboViewer depComboViewer;
	private Combo depCombo;
	//职务
	private ComboViewer posComboViewer;
	private Combo posCombo;
	//联系电话
	private Text telText;
	//入职时间
	private CalendarCombo entryCombo;
	//提交
	private Button okButton;
	//清空
	private Button clearButton;
	
	
	@Inject
	public AddPart(Composite parent) {
	}
	
	@PostConstruct
	public void postConstruct(final Composite parent) {
		GridLayout layout = new GridLayout(1, false);
		layout.marginWidth = 10;
		layout.marginHeight = 10;
		parent.setLayout(layout);
		
		Label title = new Label(parent, SWT.NONE);
		title.setFont(SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD));
		title.setText("员工登记");
		
		Composite infoComposite = new Composite(parent, SWT.NONE);
		infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		infoComposite.setLayout(new GridLayout(3, false));
		
		//姓名
		Label nameLabel = new Label(infoComposite, SWT.RIGHT);
		nameLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		nameLabel.setText("姓名：");
		nameText = new Text(infoComposite, SWT.BORDER);
		nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		new Label(infoComposite, SWT.NONE);
		
		// 性别
		Label genderLabel = new Label(infoComposite, SWT.RIGHT);
		genderLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false,
				1, 1));
		genderLabel.setText("性别：");
		genderCombo = new Combo(infoComposite, SWT.NONE);
		genderCombo.setItems(new String[] {"男", "女"});
		genderCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		new Label(infoComposite, SWT.NONE);
		
		//联系电话
		Label telLabel = new Label(infoComposite, SWT.RIGHT);
		telLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
		telLabel.setText("联系电话：");
		telText = new Text(infoComposite, SWT.BORDER);
		telText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
		new Label(infoComposite, SWT.NONE);
		
		// 部门
		Label depLabel = new Label(infoComposite, SWT.RIGHT);
		depLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		depLabel.setText("部门：");
		depComboViewer = new ComboViewer(infoComposite, SWT.READ_ONLY);
		depCombo = depComboViewer.getCombo();
		depCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
		depComboViewer.setContentProvider(ArrayContentProvider
				.getInstance());
		depComboViewer.setLabelProvider(new LabelProvider() {
			@Override
			public String getText(Object element) {
				//TODO 得到部门text
//				if (element instanceof Building) {
//					Building building = (Building) element;
//					return building.getEms_name();
//				}
				return super.getText(element);
			}
		});
		// TODO 获取部门数据
		new Label(infoComposite, SWT.NONE);
//		List<Building> buildings = EstateManager.getBuildings();
//		buildingComboViewer.setInput(buildings);
//
//		buildingComboViewer
//				.addSelectionChangedListener(new ISelectionChangedListener() {
//					@Override
//					public void selectionChanged(SelectionChangedEvent event) {
//						IStructuredSelection selection = (IStructuredSelection) event
//								.getSelection();
//						long buildingId = ((Building) selection
//								.getFirstElement()).getId();
//						// 获取楼层数据
//						List<Floor> floors = EstateManager
//								.getFloorsByBuilding(buildingId);
//						floorComboViewer.setInput(floors);
//					}
//				});
		
		// 职务
		Label posLabel = new Label(infoComposite, SWT.RIGHT);
		posLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false,
				false, 1, 1));
		posLabel.setText("职务：");
		posComboViewer = new ComboViewer(infoComposite, SWT.READ_ONLY);
		posCombo = posComboViewer.getCombo();
		posCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
		posComboViewer.setContentProvider(ArrayContentProvider
				.getInstance());
		posComboViewer.setLabelProvider(new LabelProvider() {
			@Override
			public String getText(Object element) {
				//TODO 得到职务text
				return super.getText(element);
			}
		});
		// TODO 获取职务数据
		new Label(infoComposite, SWT.NONE);
		
		// 入职时间
		Label entryLabel = new Label(infoComposite, SWT.RIGHT);
		entryLabel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER,
				false, false, 1, 1));
		entryLabel.setText("入职时间：");
		entryCombo = new CalendarCombo(infoComposite, SWT.BORDER);
		entryCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
				false, 1, 1));
		
		Composite btnComposite = new Composite(parent, SWT.NONE);
		btnComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false,
				1, 1));
		btnComposite.setLayout(new GridLayout(2, false));
		
		//查询按钮
		okButton = new Button(btnComposite, SWT.NONE);
		okButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
				false, 1, 1));
		okButton.setText("提交");
		
		//查询按钮
		clearButton = new Button(btnComposite, SWT.NONE);
		clearButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true,
				false, 1, 1));
		clearButton.setText("清空");
		
		
	}
	
	
	@PreDestroy
	public void preDestroy() {
		//TODO Your code here
	}
	
	
	
}